package com.atguigu.book.controller;

import com.atguigu.book.pojo.Cart;
import com.atguigu.book.pojo.User;
import com.atguigu.book.service.BookService;
import com.atguigu.book.service.CartItemService;
import com.atguigu.book.service.UserService;

import javax.servlet.http.HttpSession;

/**
 * @ClassName: UserController
 * @Description:
 * @Author: wty
 * @Date: 2022/12/12
 */

public class UserController {
    private UserService userService;
    private CartItemService cartItemService;

    public String login(String uname, String pwd, HttpSession session) {
        User user = userService.login(uname, pwd);
        System.out.println("user = " + user);

        if (null != user) {
            // 加载购物车的信息
            Cart cart = cartItemService.getCart(user);
            user.setCart(cart);

            // 保存的user是加载了购物车信息的user
            session.setAttribute("currUser", user);
            // 加载价格查询
            session.setAttribute("minPrice", null);
            session.setAttribute("maxPrice", null);

            return "redirect:book.do";
        } else {
            return "user/login";
        }

    }
}
